﻿using System;
using System.Linq;

namespace RayDen.Library.Components.SystemComponents
{
    public interface ITracerImplementation
    {
        void Write(string template, params object[] parameters);
        void WriteLine(string template, params object[] parameters);

    }

    public class Tracer
    {
        private static readonly DateTime AppStartTime = DateTime.UtcNow;

        public const string LevelSign= "...";

        public const string MessageTemplate = "{0} - {1}";

        static string GetLevelSign(int level)
        {
            return Enumerable.Repeat(LevelSign, level + 1).Aggregate((a, b) => a + b);
        }

        public static void Trace(string message, int level = 0, params object[] parameters)
        {
            TracerFactory.Instance.Trace(string.Format("{0} {1}", GetLevelSign(level),string.Format(message, parameters)));
        }

        public static void TraceLine(string message = null, params object[] parameters)
        {
            TracerFactory.Instance.WriteLine(string.Format("|{2}| {0} {1}", GetLevelSign(0), string.Format(message??string.Empty, parameters)??" ", (DateTime.UtcNow - AppStartTime).ToString()));
        }
    }
}
